/*
 *  Copyright 2011 yura.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.vcforms.view.component.doublelist;

import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JList;
import javax.swing.ListModel;
import org.opu.vcforms.io.Logger;

/**
 *
 * @author yura
 */
class JListImpl extends JList {

    private ActionListener action;

    public JListImpl(ListModel dataModel) {
        this(dataModel, null);
    }

    public JListImpl(ListModel dataModel, ActionListener action) {
        super(dataModel);
        this.action = action;
        addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                if (2 == e.getClickCount()) {
                    if (JListImpl.this.action != null) {
                        JListImpl.this.action.actionPerformed(null);
                    } else {
                        Logger.warning(getClass().getName() + ": "
                                + "List action is NULL !");
                    }
                }
            }
        });
    }

    public ActionListener getAction() {
        return action;
    }

    public void setAction(ActionListener action) {
        this.action = action;
    }
}
